package com.gitee.wsl.ext.collection


fun <T1, T2> Iterable<T1>.combine(other: Iterable<T2>): List<Pair<T1, T2>> =
    combine(other) { thisItem: T1, otherItem: T2 -> Pair(thisItem, otherItem) }

fun <T1, T2> Iterable<T1>.combineToMutableList(other: Iterable<T2>): MutableList<Pair<T1, T2>> =
    combineToMutableList(other) { thisItem: T1, otherItem: T2 -> Pair(thisItem, otherItem) }

inline fun <T1, T2, R> Iterable<T1>.combine(
    other: Iterable<T2>,
    transform: (thisItem: T1, otherItem: T2) -> R
): List<R> = flatMap { thisItem -> other.map { otherItem -> transform(thisItem, otherItem) } }

inline fun <T1, T2, R> Iterable<T1>.combineToMutableList(
    other: Iterable<T2>,
    transform: (thisItem: T1, otherItem: T2) -> R
): MutableList<R> = flatMapTo(mutableListOf()) { thisItem -> other.map { otherItem -> transform(thisItem, otherItem) } }
